package test;

import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;

public class FilePage 
{
  public static void main(String[] args) {
     FilePage window = new FilePage();
    window.open();
  }

   protected CheckboxTableViewer tableViewer;
   
   public void open() {
   final Display display = new Display();
      final Shell shell = new Shell();
      shell.setSize(500, 150);
      shell.setText("TableViewer的实例");

      shell.setLayout(new FillLayout());
   Composite composite = new Composite(shell, SWT.NULL);
   composite.setFont(shell.getFont());
   composite.setLayout(new GridLayout());
   composite.setLayoutData(new GridData(GridData.FILL_BOTH));

   Table table = new Table(composite, SWT.CHECK | SWT.BORDER
                               | SWT.MULTI);
       table.setLayoutData(new GridData(GridData.FILL_BOTH));
       table.setHeaderVisible(true);
       table.setLinesVisible(true);

       // Add a table layout to the table
       TableLayout tableLayout = new TableLayout();
       table.setHeaderVisible(true);
       table.setLayout(tableLayout);
       
   tableLayout.addColumnData(new ColumnWeightData(20));
   new TableColumn(table, SWT.NONE).setText("File Name");
       
   tableLayout.addColumnData(new ColumnWeightData(70));
   new TableColumn(table,SWT.NONE).setText("Description");
   // Add the viewer
   tableViewer = new CheckboxTableViewer(table);
//   tableViewer.setLabelProvider(new TableViewerLabelProvider());
//   tableViewer.setContentProvider(new TableViewerContentProvider());
//   tableViewer.setInput(PeopleFactory.getFiles());
   //addListener();
//   tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
//   public void selectionChanged(SelectionChangedEvent event) {
//   // will default to false until a selection is made    
//   IStructuredSelection selection = (IStructuredSelection)    event.getSelection();
//          //得到记录的实体对象（要类型转换）
//   PeopleEntity o = (PeopleEntity) selection.getFirstElement();
//            System.out.println(o.getName());
//               }
//       });
       
//   final Label configLabel = new Label(composite, SWT.BOTTOM);
//   configLabel.setFont(composite.getFont());
//   configLabel.setText("您所选取的文件如下:");
//   shell.open();
//    while (!shell.isDisposed()) {
//        if (!display.readAndDispatch())
//          display.sleep();
//    }
   }
}